package qianfeng.com.meijiadaka.adapter.shop_details;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import qianfeng.com.meijiadaka.R;
import qianfeng.com.meijiadaka.adapter.ShopHeadRecyclerAdapter;
import qianfeng.com.meijiadaka.bean.detail.SpecialBeanAbove;

/**
 * Created by Think on 2017/2/9.
 */

public class SpecialDetailsLvItem2Adapter extends RecyclerView.Adapter<SpecialDetailsLvItem2Adapter.MyViewHolder> {

    private Context context;
    List<SpecialBeanAbove.ResultBean.CommoditiesBean> list;
    ShopHeadRecyclerAdapter.OnItemClickListener mListener;
    private RecyclerView rv;

    public SpecialDetailsLvItem2Adapter(Context context, List<SpecialBeanAbove.ResultBean.CommoditiesBean> list) {
        this.context = context;
        this.list = list;
        Log.e("SpecialDetailsLvItem2Adapter: ",list.size()+"");
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        rv = recyclerView;
    }

    public interface OnItemClickListener{
        void onClick(int index);
    }
    public void setOnItemClickListener(ShopHeadRecyclerAdapter.OnItemClickListener itemClickListener) {
        this.mListener=itemClickListener;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(context).inflate(R.layout.specia_details_list_item2_rvitem,parent,false);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mListener!=null){
                    mListener.onClick(rv.getChildAdapterPosition(view));
                }
            }
        });
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv.setText(list.get(position).getCommodityName());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView tv;
        public MyViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.specia_details_list_item2_rv_tv);
        }
    }


}
